#!/usr/bin/env python
#
# Copyright 2007 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
from google.appengine.ext import webapp
from google.appengine.ext.webapp import util
from django.utils import simplejson as json

class DBAdd(webapp.RequestHandler):
    def add2db(self,dbname,data):
        datalist=json.loads(data)
        for date in data.keys():
            self.response.out.write(date)
            self.response.out.write('<br>')
    def get(self):
        self.response.out.write('class DBAdd<br>')
        
        dbname=self.request.get('dbname')
        if dbname=='':
            self.response.out.write('ERROR:Need DB Name')
            return
        if dbname in ['month','week','day']:
            data=self.request.get('data')
            self.add2db(dbname,data)
        else:
            self.response.out.write('ERROR:DB Name Not Exist')
            return
            


def main():
    application = webapp.WSGIApplication([('/add', DBAdd)],
                                         debug=True)
    util.run_wsgi_app(application)


if __name__ == '__main__':
    main()
